package com.mdp.im.core.publish.action;


import com.alibaba.fastjson.JSONObject;
import com.mdp.im.core.plugin.api.PublishPlugin;
import com.mdp.im.core.publish.api.action.PublishAction;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * 消息处理抽象类
 * 
 * @author chenyc
 * @date 2018/5/15
 */
public class AbstractPublishAction implements PublishAction {

    @Autowired(required = false)
    List<PublishPlugin> plugins;

    @Override
    public void doAction(JSONObject message) {

    }

    public boolean execusePlugins(JSONObject message){
        boolean go=true;
        if(plugins!=null && plugins.size()>0){

            for (int i = 0; i < plugins.size(); i++) {
                go = plugins.get(i).beforePublish(message);
                if(go==false){
                    return false;
                }
            }
        }
        return true;
    }



}
